import Vue from 'vue'
import Vuex from 'vuex'

import {
  testPaperQuery,
  testPaperDelete,
  testPaperAdd,
  testPaperUpdate,
} from '@/api/admin/exam/testPaper'

Vue.use(Vuex)

const state = {
  activeName: 'manage',
  activeRow: {},
}

const getters = {}

const actions = {
  //试题增删改查
  async testPaperList({ commit }, listQuery) {
    let res = await testPaperQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async testPaperDel({ commit }, row) {
    let res = await testPaperDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async testPaperADD({ commit }, data) {
    let res = await testPaperAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async testPaperUPDATE({ commit }, data) {
    let res = await testPaperUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {
  SET_ACTIVENAME: (state, d) => {
    state.activeName = d
  },
  SET_ACTIVEROW: (state, d) => {
    state.activeRow = d
  },
}

export default {
  state,
  getters,
  actions,
  mutations,
}
